package SwordFingerOffer;

public class Q11_RotateArrayMinVal {

    //旋转数组含重复值最小值 二分
    //想复杂了 只考虑一边的情况就可以了
    public static int minArray(int[] numbers) {
        if (numbers == null || numbers.length == 0){
            return Integer.MAX_VALUE;
        }

        int left = 0;
        int right = numbers.length - 1;
        int mid = -1;
        while (left < right){

//            mid = left + ((right - left) >> 2) ;
            mid = (left + right) / 2;
            //小于 mid右边全部淘汰 不包括mid
            //因为mid有可能是答案
            if (numbers[mid] < numbers[right]){
                right = mid;
                //大于的话，包括mid及其左边全部淘汰
            }else if (numbers[mid] > numbers[right]){
                left = mid + 1;
                //等于的话
            }else {
                // [mid] == [right]
                right--;
            }
        }
        return numbers[left];
    }

    public static void main(String[] args) {
        System.out.println(minArray(new int[]{3,3,1,3}));
    }
}
